package com.junt.library.model;

import android.net.Uri;

/**
 * 媒体数据类
 */
public class Media {

    //仅用于选择界面，标识该项是否选中
    private boolean isChecked;

    /**
     * uri
     */
    private final Uri uri;
    /**
     * 文件名
     */
    private final String name;
    /**
     * 文件尺寸，字节
     */
    private final long size;
    /**
     * 音、视频的时长，毫秒
     */
    private final long duration;
    /**
     * 文件创建时间，秒
     */
    private final long dateAdded;
    /**
     * 文件最近修改时间，秒
     */
    private long dateModified;

    /**
     * eg: video/*
     */
    private String mimeType;

    /**
     * The orientation for the media item, expressed in degrees. For
     * example, 0, 90, 180, or 270 degrees.
     */
    private int orientation;

    /**
     * The width/height of the media item, in pixels.
     */
    private int width, height;

    /**
     * The resolution of video files,such as 'XxY'
     */
    private String resolution;

    /**
     * 相对路径
     * eg：For example, an item stored at
     * {@code /storage/0000-0000/DCIM/Vacation/IMG1024.JPG} would have a
     * path of {@code DCIM/Vacation/}.
     */
    private String relativePath;

    /**
     * 绝对路径
     */
    private String absolutePath;

    public Media(
            Uri uri,
            String name,
            long size,
            long duration,
            long dateModified,
            long dateAdded,
            String mimeType,
            int orientation,
            int width,
            int height,
            String resolution,
            String relativePath,
            String absolutePath) {
        this.uri = uri;
        this.name = name;
        this.size = size;
        this.duration = duration;
        this.dateModified = dateModified;
        this.dateAdded = dateAdded;
        this.mimeType = mimeType;
        this.orientation = orientation;
        this.width = width;
        this.height = height;
        this.resolution=resolution;
        this.relativePath = relativePath;
        this.absolutePath = absolutePath;
    }

    public Uri getUri() {
        return uri;
    }

    public String getName() {
        return name == null ? "" : name;
    }

    public long getSize() {
        return size;
    }

    public String getRelativePath() {
        return relativePath == null ? "" : relativePath;
    }

    public String getAbsolutePath() {
        return absolutePath == null ? "" : absolutePath;
    }

    public long getDuration() {
        return duration;
    }

    public long getDateAdded() {
        return dateAdded;
    }

    public long getDateModified() {
        return dateModified;
    }

    public boolean isImage() {
        return mimeType != null && mimeType.contains("image");
    }

    public boolean isVideo() {
        return mimeType != null && mimeType.contains("video");
    }

    public boolean isAudio() {
        return mimeType != null && mimeType.contains("audio");
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }


    @Override
    public String toString() {
        return "Media{\n" +
                " uri=" + uri +
                ", name='" + name + '\n' +
                ", size=" + size + '\n' +
                ", duration=" + duration + '\n' +
                ", dateModified=" + dateModified + '\n' +
                ", mimeType='" + mimeType + '\n' +
                ", orientation=" + orientation + '\n' +
                ", width=" + width + '\n' +
                ", height=" + height + '\n' +
                ", resolution=" + resolution + '\n' +
                ", relativePath='" + relativePath + '\n' +
                ", absolutePath='" + absolutePath + '\n' +
                '}';
    }
}
